import Vue from 'vue';
import App from './App';
import router from './router';
import axios from 'axios';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';   // 默认主题
// import '../static/css/theme-green/index.css';       // 浅绿色主题
import "babel-polyfill";
import 'global.js';

Vue.use(ElementUI);
Vue.prototype.$axios = axios;
new Vue({
    router,
    render: h => h(App)
}).$mount('#app');

router.beforeEach((to, from, next) => {
    let auth_str = localStorage.getItem('auth_list')
    let isLogin = localStorage.getItem('ms_username')
    // console.log(to)
    if (to.matched.some(m => m.path !== '/')) {
        // 如果路由是进入首页
        if (to.path === '/readme') {
            // 如果没有权限,进入空白页
            if(auth_str.indexOf('analysis-list')<0){
                next({path: '/nullpage'})
            } else {
                next();
            }
        } else {
            // 不是进入首页
            if (to.meta.auth_name != undefined && auth_str.indexOf(to.meta.auth_name) >= 0) {
                // console.log('拥有路由锁，进入的页面拥有权限')
                next();
            } else if(auth_str.indexOf(to.meta.auth_name) < 0 && to.meta.auth_name != undefined){
                // console.log('拥有路由锁，但是没有权限')
                alert('权限不足!')
                return
            } else if (to.meta.auth_name == undefined){
                // console.log('没有路由锁')
                next()
            } else if(to.path === '/login'){
                // console.log('退出')
                next();
            }else {
                // console.log('路径：' + to.path,',路由锁：' + to,', 是否含有：' + auth_str.indexOf(to.meta.auth_name))
                // console.log(to)
                // console.log('嗯哼')
                next({ path: '/' });
            }
        }
    }
})
axios.defaults.withCredentials = true